/*
 * TemplateListPanel.java
 *
 * Created on 12. Juni 2008, 01:38
 */

package twi.query.template2.view;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.ArrayList;

import twi.query.template2.Template;
import twi.query.template2.TemplateLibrary;
import twi.user.User;
import twi.view.QueryPanel;
import twi_project.TWI;

/**
 *
 * @author  Soeren
 */
public class TemplateListPanel extends javax.swing.JPanel implements QueryPanel{

    /** Creates new form TemplateListPanel */
    public TemplateListPanel() {
        initComponents();
        
    }
    private void updateList(){
    	User user = TWI.getInstance().getCurrentUser();
        ArrayList<Template> list = TemplateLibrary.getTemplates(user);
        this.jPanel1.setLayout(new GridBagLayout());
        GridBagConstraints gc = new GridBagConstraints();
        this.jPanel1.removeAll();
        gc.fill = GridBagConstraints.BOTH;
        gc.gridheight = 1;
        gc.gridwidth = 1;
        gc.gridx = 0;
        gc.gridy = 0;
        for (int i = 0; i < list.size(); i++){
        	this.jPanel1.add(new TemplatePreviewPanel(list.get(i)), gc);
        	gc.gridy++;
        }
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();

        setName("Form"); // NOI18N
        setLayout(new java.awt.BorderLayout());

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setLayout(new java.awt.GridBagLayout());
        jScrollPane1.setViewportView(jPanel1);

        add(jScrollPane1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
	@Override
	public void setFocus() {
		updateList();
	}

}
